//* 检查必填项(返回提示信息) verifyInputFieldReturn(fieldIds)
//* 校验登录名，弹框提示,返回boolean。 function checkLoginName(fieldId)
//* 校验登录名，弱提示,返回boolean。 function checkLoginNameWeak(fieldId)
//* 检查长度(返回提示信息) verifyInputLengthReturn(fieldIds, minLength, maxLength)
//* 校验手机(返回提示信息) isPhoneReturn(fieldIds)
//* 显示输入框后的正确或错误信息(提示信息的div的id为“jqId_msg”格式)showMsgAndFocus(message,jqId,status)
//* verifyInputFieldShow(fieldIds)
function trimAllSpace(Str) {
	return $.trim(trimChSpace($.trim(Str)));
}
function trimChSpace(mystr) {
	if (mystr == null || typeof(mystr) == "undefined" || mystr.length < 1)
		return "";
	var chSpace = "　";
	while ((mystr.indexOf(chSpace) == 0) && (mystr.length > 1)) {
		mystr = $.trim(mystr.substring(1, mystr.length));
	}
	while ((mystr.lastIndexOf(chSpace) == mystr.length - 1)
			&& (mystr.length > 1)) {
		mystr = $.trim(mystr.substring(0, mystr.length - 1));
	}
	if (mystr == chSpace) {
		mystr = "";
	}
	return mystr;
}
//校验登录名，弹框提示,返回boolean。(规则：以字母开头，并由字母、数字组成)
function checkLoginName(fieldId){
	var jqId = "#"+fieldId;
	if(!/^[a-zA-Z][a-zA-Z0-9]*$/i.test($(jqId).val())) {
		alertWarnMsgDialog($(jqId).attr("title")+"格式错误，请以字母开头，并只能由字母或数字组成！");
		return false;
	}else{
		return true;	
	}
}
//校验登录名，弱提示,返回boolean。(规则：以字母开头，并由字母、数字组成)
function checkLoginNameWeak(fieldId){
	var jqId = "#"+fieldId;
	if(!/^[a-zA-Z][a-zA-Z0-9]*$/i.test($(jqId).val())) {
		alertMsgAndFocus($(jqId).attr("title")+"格式错误，请以字母开头，并只能由字母或数字组成",jqId);
		return false;
	}else{
		return true;	
	}
}
function closeAllDialog() {
	var list = art.dialog.list;
	for (var i in list) {
		list[i].close();
	};
}

function showLoading(title) {
	var list = art.dialog.list;
	for (var i in list) {
		list[i].close();
	};
	return art.dialog({
				esc : true,
				lock : true,
				title : title,
				fixed : true,
				drag : false
			});
}
function alertMsg(message) {
	showPromptBox(message);
}
// 弹出窗式的提示信息，message为提示的内容
function alertWarnMsgDialog(msg) {
	alertMsgDialog(msg, "warning");
}

function alertSuccMsgDialog(msg){ 
	alertMsgDialog(msg, "succeed");
}

function alertErrorMsgDialog(msg){
	alertMsgDialog(msg, "error");
}

function alertQuestionMsgDialog(msg){
	alertMsgDialog(msg, "question");
}

function alertLoadingMsgDialog(msg){
	alertMsgDialog(msg, "loading");
}

function alertMsgDialog(message, icon) {
	var list = art.dialog.list;
	for (var i in list) {
		list[i].close();
	};
	art.dialog({
				icon : icon,
				esc : true,
				content : message,
				lock : true,
				fixed : true,
				drag : false,
				ok : true,
				init : function() {
					var that = this, i = 10;
					var fn = function() {
						that.title(i + '秒后自动关闭');
						!i && that.close();
						i--;
					};
					tip_timer = setInterval(fn, 1000);
					fn();
				},
				close : function() {
					clearInterval(tip_timer);
				}
			}).time(10);
}
function alertMsgDialogSetTitle(title, message, icon) {
	var list = art.dialog.list;
	for (var i in list) {
		list[i].close();
	};
	art.dialog({
				icon : icon,
				esc : true,
				content : message,
				lock : true,
				fixed : true,
				drag : false,
				ok : true,
				title : title,
				init : function() {
					var that = this, i = 10;
					var fn = function() {
						that.title(title + "(" + i + ")");
						!i && that.close();
						i--;
					};
					tip_timer = setInterval(fn, 1000);
					fn();
				},
				close : function() {
					clearInterval(tip_timer);
				}
			}).time(10);
}
function alertMsgDialogAndJump(message, icon, jumpUrl) {
	var list = art.dialog.list;
	for (var i in list) {
		list[i].close();
	};
	art.dialog({
				icon : icon,
				esc : true,
				content : message,
				lock : true,
				fixed : true,
				drag : false,
				ok : true,
				init : function() {
					var that = this, i = 10;
					var fn = function() {
						that.title(i + '秒后自动关闭');
						!i && that.close();
						i--;
					};
					tip_timer = setInterval(fn, 1000);
					fn();
				},
				close : function() {
					clearInterval(tip_timer);
					showRightContent(jumpUrl);
				}
			}).time(10);
}
function alertMsgDialogSetTitleAndJump(title, message, icon, jumpUrl) {
	var list = art.dialog.list;
	for (var i in list) {
		list[i].close();
	};
	art.dialog({
				icon : icon,
				esc : true,
				content : message,
				lock : true,
				fixed : true,
				drag : false,
				ok : true,
				title : title,
				init : function() {
					var that = this, i = 10;
					var fn = function() {
						that.title(title + "(" + i + ")");
						!i && that.close();
						i--;
					};
					tip_timer = setInterval(fn, 1000);
					fn();
				},
				close : function() {
					clearInterval(tip_timer);
					showRightContent(jumpUrl);
				}
			}).time(10);
}
function alertMsgAndFocus(message, jqId) {
	$(jqId).focus();
	showPromptBox(message);
}
function alertMsgAndFocus_pop(message, jqId) {
	$(jqId).focus();
	showPopPromptBox(message);
}
function confirmMsg(message) {
	var list = art.dialog.list;
	for (var i in list) {
		list[i].close();
	};
	art.dialog({
				esc : true,
				content : message,
				lock : true,
				fixed : true,
				drag : false,
				ok : function(){return 0;},
				cancel:function(){return 1;},
				init : function() {
					var that = this, i = 10;
					var fn = function() {
						that.title(i + '秒后自动关闭');
						!i && that.close();
						i--;
					};
					tip_timer = setInterval(fn, 1000);
					fn();
				},
				close : function() {
					clearInterval(tip_timer);
					cancelFunction;
				}
			}).time(10);
}


function showMsgAndFocus(message,jqId,status){
	var msgId = jqId+"_msg";
	$(msgId).html("");
	if(status){
		$(msgId).html("");
	}else{
		$(msgId).css("color","red");
		$(msgId).html(message);
	}
}

function verifyInputField(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		if ($(jqId).length <= 0)
			continue;
		var val = trimAllSpace(($(jqId).val()));
		$(jqId).val(val);
		if (!val) {
			alertMsgAndFocus("请输入" + $(jqId).attr("title"), jqId);
			return false;
		}
	}
	return true;
}
function verifyInputField_pop(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		if ($(jqId).length <= 0)
			continue;
		var val = trimAllSpace(($(jqId).val()));
		$(jqId).val(val);
		if (!val) {
			alertMsgAndFocus_pop("请输入" + $(jqId).attr("title"), jqId);
			return false;
		}
	}
	return true;
}
// 检查必填项(返回提示信息)
function verifyInputFieldReturn(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		if ($(jqId).length <= 0)
			continue;
		var val = trimAllSpace(($(jqId).val()));
		$(jqId).val(val);
		if (!val) {
			return "请输入"+ $(jqId).attr("title")+"!";
		}
	}
	return "true";
}

// 检查必填项并显示msg(返回校验是否通过)
function verifyInputFieldShow(fieldIds) {
	var status = true;
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		if ($(jqId).length <= 0)
			continue;
		var val = trimAllSpace(($(jqId).val()));
		$(jqId).val(val);
		if (!val) {
			status = false;
			showMsgAndFocus("请输入"+ $(jqId).attr("title"),jqId,status);
		}else{
			showMsgAndFocus("请输入"+ $(jqId).attr("title"),jqId,true);
		}
	}
	return status;
}
// 检查长度并显示msg(返回校验是否通过)
function verifyInputLengthShow(fieldIds, minLength, maxLength) {
	var status = true;
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		var value = trimAllSpace($(jqId).val());
		$(jqId).val(value);
		var reallen = value.length;
		var i = true;
		if (reallen < minLength) {
			status = false;
			i = false;
			showMsgAndFocus(($(jqId).attr("title") + "少于" + minLength
							+ "个字符,已输入" + reallen + "个字符"),jqId,status);
		}
		if (reallen > maxLength) {
			status = false;
			i = false;
			showMsgAndFocus(($(jqId).attr("title") + "超过" + minLength
							+ "个字符,已输入" + reallen + "个字符"),jqId,status);
		}
		if(i){
			showMsgAndFocus("",jqId,true);
		}
	}
	return status;
}

function verifyCheckboxFieldShow(fieldName, fieldTitle, fieldId) {
	var ch = $("input[name=" + fieldName + "]:checkbox:checked").size();
	if (ch > 0) {
		showMsgAndFocus("","#"+fieldId,true);
		return true;
	} else {
		showMsgAndFocus(("请选择" + fieldTitle),"#"+fieldId,false);
		return false;
	}
}

function verifyInputLength(fieldIds, minLength, maxLength) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		var value = trimAllSpace($(jqId).val());
		$(jqId).val(value);
		var reallen = value.length;
		if (reallen < minLength) {
			alertMsgAndFocus(($(jqId).attr("title") + "少于" + minLength
							+ "个字符,已输入" + reallen + "个字符"), jqId);
			return false;
		}
		if (reallen > maxLength) {
			alertMsgAndFocus(($(jqId).attr("title") + "超过" + maxLength
							+ "个字符,已输入" + reallen + "个字符"), jqId);
			return false;
		}
	}
	return true;
}
function verifyInputLength_pop(fieldIds, minLength, maxLength) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		var value = trimAllSpace($(jqId).val());
		$(jqId).val(value);
		var reallen = value.length;
		if (reallen < minLength) {
			alertMsgAndFocus(($(jqId).attr("title") + "不可少于" + minLength
							+ "个字符,已输入" + reallen + "个字符"), jqId);
			return false;
		}
		if (reallen > maxLength) {
			alertMsgAndFocus(($(jqId).attr("title") + "不可超过" + maxLength
							+ "个字符,已输入" + reallen + "个字符"), jqId);
			return false;
		}
	}
	return true;
}
// 检查长度(返回提示信息)
function verifyInputLengthReturn(fieldIds, minLength, maxLength) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		var value = trimAllSpace($(jqId).val());
		$(jqId).val(value);
		var reallen = value.length;
		if (reallen < minLength) {
			return $(jqId).attr("title") + "少于" + minLength
							+ "个字符,已输入" + reallen + "个字符";
		}
		if (reallen > maxLength) {
			return $(jqId).attr("title") + "超过" + maxLength
							+ "个字符,已输入" + reallen + "个字符";
		}
	}
	return "true";
}
function verifyValueEqual(fieldId1, fieldId2) {
	var jqId1 = "#" + fieldId1;
	var jqId2 = "#" + fieldId2;
	if ($(jqId1).val() != $(jqId2).val()) {
		alertMsgAndFocus($(jqId1).attr("title") + "与" + $(jqId2).attr("title")
						+ "不相同！", jqId2);
		$(jqId2)[0].select();
		return false;
	}
	return true;
}
function isEmail(fieldId) {
	var jqId = "#" + fieldId;
	var email = $(jqId).val();
	if (!validateEmail(email)) {
		alertMsgAndFocus($(jqId).attr("title") + "不合法！", jqId);
		$(jqId)[0].select();
		return false;
	} else {
		return true;
	}
}
function validateEmail(email) {
	var at = email.lastIndexOf("@");
	if (at < 1 || (at + 1) === email.length)
		return false;
	if (/(\.{2,})/.test(email))
		return false;
	var local = email.substring(0, at);
	var domain = email.substring(at + 1);
	if (local.length < 1 || local.length > 64 || domain.length < 4
			|| domain.length > 255)
		return false;
	if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
		return false;
	if (!/^"(.+)"$/.test(local)) {
		if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
			return false;
	}
	if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
		return false;
	return true;
}
function isPhone(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		var value = $(jqId).val();
		if (value != null && value != '') {
			if (!isMobilePhone(value)) {
				alertMsgAndFocus($(jqId).attr("title") + "不合法！", jqId);
				$(jqId)[0].select();
				return false;
			}
		}
	}
	return true;
}
//校验手机(返回提示信息)
function isPhoneReturn(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		var value = $(jqId).val();
		if (value != null && value != '') {
			if (!isMobilePhone(value)) {
				return $(jqId).attr("title") + "不合法！";
				$(jqId)[0].select();
			}
		}
	}
	return "true";
}
function isTel(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		$(jqId).val(trimAllSpace($(jqId).val()));
		if ($(jqId).val()) {
			var pattern = /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/;
			if (!pattern.test($(jqId).val())) {
				alertMsgAndFocus($(jqId).attr("title") + "不合法！", jqId);
				$(jqId)[0].select();
				return false;
			}
		}
	}
	return true;
}

//只匹配 括号、数字、- 等符号的手机号码
function checkTel(fieldIds) {
    var ids = fieldIds.split(",");
    for (var i = 0; i < ids.length; i++) {
        var jqId = "#" + ids[i];
        $(jqId).val(trimAllSpace($(jqId).val()));
        if ($(jqId).val()) {
            var pattern = /^[0-9-()\s]{0,20}$/;
            if (!pattern.test($(jqId).val())) {
                alertMsgAndFocus($(jqId).attr("title") + "不合法！", jqId);
                $(jqId)[0].select();
                return false;
            }
        }
    }
    return true;
}

function verifyCheckboxField(fieldName, fieldTitle) {
	var ch = $("input[name=" + fieldName + "]:checkbox:checked").size();
	if (ch > 0) {
		return true;
	} else {
		alertMsg("请选择" + fieldTitle + "！");
		return false;
	}
}
function verifyRadioField(fieldName, fieldTitle) {
	var ch = $("input[name=" + fieldName + "]:radio:checked").size();
	if (ch > 0) {
		return true;
	} else {
		alertMsg("请选择" + fieldTitle + "！");
		return false;
	}
}
function verifySelectField(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		if ($(jqId).val() == "" || $(jqId).val() <= 0) {
			alertMsgAndFocus("请选择" + $(jqId).attr("title"), jqId);
			return false;
		}
	}
	return true;
}
function verifyLoginName(fieldId) {
	var jqId = "#" + fieldId;
	var username = trimAllSpace($(jqId).val());
	$(jqId).val(username);
	var title = $(jqId).attr("title");
	if (/^\d.*$/.test(username)) {
		alertMsgAndFocus(title + "不能以数字开头！", jqId);
		$(jqId)[0].select();
		return false;
	} else if (fLen(username) < 5) {
		alertMsgAndFocus(title + "不能少于6个字符！", jqId);
		$(jqId)[0].select();
		return false;
	} else if (!/^\w+$/.test(username)) {
		alertMsgAndFocus(title + "只能输入字母、数字和下划线！", jqId);
		$(jqId)[0].select();
		return false;
	} else if (!/^([a-z]|[A-Z])[0-9a-zA-Z_]+$/.test(username)) {
		alertMsgAndFocus(title + "只能以字母开头！", jqId);
		$(jqId)[0].select();
		return false;
	} else if (!(/[0-9a-zA-Z]+$/.test(username))) {
		alertMsgAndFocus(title + "只能以英文字母或数字结尾！", jqId);
		$(jqId)[0].select();
		return false;
	}
	return true;
}
function verifyPassword(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		var value = $(jqId).val();
		if (strLen(value) != value.length) {
			alertMsgAndFocus($(jqId).attr("title") + "不合法！", jqId);
			$(jqId)[0].select();
			return false;
		}
	}
	return true;
}
function strLen(value) {
	var strlen = value.replace(/[^\x00-\xff]/g, "xx").length;
	return strlen;
}
function fLen(Obj) {
	var nCNLenth = 0;
	var nLenth = Obj.length;
	for (var i = 0; i < nLenth; i++) {
		if (Obj.charCodeAt(i) > 255) {
			nCNLenth += 2;
		} else {
			nCNLenth++;
		}
	}
	return nCNLenth;
}
function selectAll(flag) {
	$("input[name='keyIds']").each(function() {
				if (!this.disabled)
					this.checked = flag;
			});
}

/**
 * 验证是否是数字
 * 
 * @param {}
 *            strValue
 * @return {}
 */
function IsNumber(strValue) {
	return checkExp(/^\d*$/g, strValue);
}

function checkExp(re, s) {
	return re.test(s);
}

/** 验证是否是手机号码  */
function isMobilePhone(tel)
{
   var mobile = /^1[3|4|5|7|8]\d{9}$/;
   return mobile.test(tel);
}

/** 验证是否是是邮编  */
function IsPostId(str)
{
var reg=/^\d{6}$/;
return reg.test(str);
}


/** 获取访问root路径  */
function getRootUrl()
{	
	/**
	//获取整个访问路径
 	var curWwwPath=window.document.location.href;  
    //获取主机地址之后的目录
    var pathName=window.document.location.pathname; 
     
    var pos=curWwwPath.indexOf(pathName);  
    //获取主机地址，如： http://localhost:8080  
    var localhostPaht=curWwwPath.substring(0,pos);  
    //获取带"/"的项目名，如：/user
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+2); 
    **/ 
    return($("#projectRootUrl").val());  
}

function checkPhoneAndShow(phone,fieldId)
{
	var isPhone = isMobilePhone(phone);
	if(isPhone){
		showMsgAndFocus("","#"+fieldId,isPhone);
	}else{
		showMsgAndFocus("手机号码不合法","#"+fieldId,isPhone);
	}
	return isPhone;
}

// 点击左侧菜单加载右侧内容 (#main_cont 未定义)
function showRightContent(contentPage) {
	$("#main_cont").hide();
	if (contentPage.indexOf("?") > 0) {
		contentPage += "&t=" + Math.random();
	} else {
		contentPage += "?t=" + Math.random();
	}
	contentPage = encodeURI(contentPage);
	$.post(contentPage, function(data) {
				$("#main_cont").empty().html(data).fadeIn();
					//下面段代码，用于解决所有文本框无法获得焦点问题，请勿删除 ----------
					$("#nouse").show();
					$("#nouse").focus();
					$("#nouse").hide();
					//--------------------------------------------------------
			});
}